package com.lyh.hkcloud.util.http.listener.handler;

import com.loopj.android.http.TextHttpResponseHandler;
import com.lyh.hkcloud.util.base.LogUtil;
import com.lyh.hkcloud.util.http.listener.text.TextFailuredListener;
import com.lyh.hkcloud.util.http.listener.text.TextSuccessListener;
import cz.msebera.android.httpclient.Header;

public class TextHttpResponseHandlerImpl extends TextHttpResponseHandler {
    private TextSuccessListener successListener;
    private TextFailuredListener failuredListener;

    public TextHttpResponseHandlerImpl(TextSuccessListener successListener, TextFailuredListener failuredListener) {
        this.successListener = successListener;
        this.failuredListener = failuredListener;
    }
    @Override
    public void onSuccess(int statusCode, Header[] headers, String response) {
        try {
            LogUtil.i("request", response.toString());
            if(successListener!=null) {
                successListener.onRespone("", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            if(failuredListener!=null) {
                failuredListener.onRespone(e.getMessage(), "");
            }
        }
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
        if(failuredListener!=null) {
            failuredListener.onRespone(throwable.getMessage(), responseString);
        }
    }

}
